package com.example.tool.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

import com.example.tool.R;

/**
 * Created Date 2020/4/26.
 *
 * @author liangkun
 * ClassDescription：
 */
public class MatrixView extends AppCompatImageView {
    Context context;

    private Matrix mMatrix;

    private float[] m;

    private int i = 1;
    private Bitmap bitmap;


    public MatrixView(Context context) {
        super(context);
//        m = new float[]{1, 0, 0, 0, 1, 0, 0, 0, 1};
        mMatrix = new Matrix();
//        mMatrix.setValues(m);
        this.context = context;
    }

    public MatrixView(Context context, AttributeSet attrs) {
        super(context, attrs);
//        m = new float[]{1, 0, 0, 0, 1, 0, 0, 0, 1};
        mMatrix = new Matrix();
//        mMatrix.setValues(m);
        this.context = context;
    }

    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (bitmap != null) {

            canvas.drawBitmap(bitmap, mMatrix, new Paint());
        }
    }

    public void change(Matrix matrix, int resid) {
        mMatrix = matrix;
        bitmap = BitmapFactory.decodeResource(context.getResources(), resid);
        invalidate();

    }

    public Matrix getImageMatrix() {
        return mMatrix;
    }
}
